package com.margo.project.web.mvcconfig.formatterRegistry;

import java.io.Serializable;
import java.text.ParseException;
import java.util.Locale;

import org.springframework.format.Formatter;
import org.springframework.util.StringUtils;

public class StringConverterFormatter implements Formatter<String>,Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public String print(String value, Locale locale) {
		  if(value == null) {  
              return "";  
          }  
          return value.toString();
	}

	@Override
	public String parse(String value, Locale locale) throws ParseException {
		String strIds = "";
		String[] objIdLists = StringUtils.split(value, ";");
		for (String id : objIdLists) {
			if (!StringUtils.isEmpty(strIds)) {
				strIds = strIds + ",'" + id + "'";
			} else {
				strIds = "'" + id + "'";
			}
		}
		return strIds;
	}

}
